package com.ruoyi.project.system.jgg.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.jgg.domain.TbBaseJgg;
import com.ruoyi.project.system.jgg.service.ITbBaseJggService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 指标分类Controller
 * 
 * @author ruoyi
 * @date 2021-12-30
 */
@Controller
@RequestMapping("/system/jgg")
public class TbBaseJggController extends BaseController
{
    private String prefix = "system/jgg";

    @Autowired
    private ITbBaseJggService tbBaseJggService;

    @RequiresPermissions("system:jgg:view")
    @GetMapping()
    public String jgg()
    {
        return prefix + "/jgg";
    }

    /**
     * 查询指标分类列表
     */
    @RequiresPermissions("system:jgg:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbBaseJgg tbBaseJgg)
    {
        startPage();
        List<TbBaseJgg> list = tbBaseJggService.selectTbBaseJggList(tbBaseJgg);
        return getDataTable(list);
    }

    /**
     * 导出指标分类列表
     */
    @RequiresPermissions("system:jgg:export")
    @Log(title = "指标分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbBaseJgg tbBaseJgg)
    {
        List<TbBaseJgg> list = tbBaseJggService.selectTbBaseJggList(tbBaseJgg);
        ExcelUtil<TbBaseJgg> util = new ExcelUtil<TbBaseJgg>(TbBaseJgg.class);
        return util.exportExcel(list, "指标分类数据");
    }

    /**
     * 新增指标分类
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存指标分类
     */
    @RequiresPermissions("system:jgg:add")
    @Log(title = "指标分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbBaseJgg tbBaseJgg)
    {
        return toAjax(tbBaseJggService.insertTbBaseJgg(tbBaseJgg));
    }

    /**
     * 修改指标分类
     */
    @RequiresPermissions("system:jgg:edit")
    @GetMapping("/edit/{dimensionCd}")
    public String edit(@PathVariable("dimensionCd") String dimensionCd, ModelMap mmap)
    {
        TbBaseJgg tbBaseJgg = tbBaseJggService.selectTbBaseJggByDimensionCd(dimensionCd);
        mmap.put("tbBaseJgg", tbBaseJgg);
        return prefix + "/edit";
    }

    /**
     * 修改保存指标分类
     */
    @RequiresPermissions("system:jgg:edit")
    @Log(title = "指标分类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbBaseJgg tbBaseJgg)
    {
        return toAjax(tbBaseJggService.updateTbBaseJgg(tbBaseJgg));
    }

    /**
     * 删除指标分类
     */
    @RequiresPermissions("system:jgg:remove")
    @Log(title = "指标分类", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbBaseJggService.deleteTbBaseJggByDimensionCds(ids));
    }
}
